package com.factory.entity;

import java.util.Date;

public class SalaryRecord {
    private Integer recordId;
    private Integer empId;
    private Double baseSalary;
    private Double bonus;
    private Double deduction;
    private Double totalSalary;
    private Date salaryMonth;
    private Date payDate;

    // 多对一关系：多条工资记录属于一个员工
    private Employee employee;

    // 构造方法
    public SalaryRecord() {}

    public SalaryRecord(Integer empId, Double baseSalary, Double bonus,
                        Double deduction, Date salaryMonth) {
        this.empId = empId;
        this.baseSalary = baseSalary;
        this.bonus = bonus;
        this.deduction = deduction;
        this.totalSalary = baseSalary + bonus - deduction;
        this.salaryMonth = salaryMonth;
    }

    // Getter和Setter方法
    public Integer getRecordId() { return recordId; }
    public void setRecordId(Integer recordId) { this.recordId = recordId; }

    public Integer getEmpId() { return empId; }
    public void setEmpId(Integer empId) { this.empId = empId; }

    public Double getBaseSalary() { return baseSalary; }
    public void setBaseSalary(Double baseSalary) {
        this.baseSalary = baseSalary;
        calculateTotalSalary();
    }

    public Double getBonus() { return bonus; }
    public void setBonus(Double bonus) {
        this.bonus = bonus;
        calculateTotalSalary();
    }

    public Double getDeduction() { return deduction; }
    public void setDeduction(Double deduction) {
        this.deduction = deduction;
        calculateTotalSalary();
    }

    public Double getTotalSalary() { return totalSalary; }
    public void setTotalSalary(Double totalSalary) { this.totalSalary = totalSalary; }

    public Date getSalaryMonth() { return salaryMonth; }
    public void setSalaryMonth(Date salaryMonth) { this.salaryMonth = salaryMonth; }

    public Date getPayDate() { return payDate; }
    public void setPayDate(Date payDate) { this.payDate = payDate; }

    public Employee getEmployee() { return employee; }
    public void setEmployee(Employee employee) { this.employee = employee; }

    private void calculateTotalSalary() {
        if (baseSalary != null && bonus != null && deduction != null) {
            this.totalSalary = baseSalary + bonus - deduction;
        }
    }

    @Override
    public String toString() {
        return "SalaryRecord{recordId=" + recordId + ", empId=" + empId +
                ", totalSalary=" + totalSalary + ", salaryMonth=" + salaryMonth + "}";
    }
}